package io.github.talelin.latticy.controller.api;

import io.github.talelin.latticy.common.annotation.ScopeLevel;
import io.github.talelin.latticy.dto.CollectMarkDTO;
import io.github.talelin.latticy.service.CollectFlowerService;
import io.github.talelin.latticy.vo.DeletedVO;
import io.github.talelin.latticy.vo.PageResponseVO;
import io.github.talelin.latticy.vo.SendCollectFlowerVO;
import io.github.talelin.latticy.vo.UpdatedVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.Positive;

@RestController
@RequestMapping("/api/collect-flower")
public class CollectController
{
    @Autowired
    private CollectFlowerService collectFlowerService;

    /**
     * 是否有收礼
     */
    @GetMapping
    @ScopeLevel
    public SendCollectFlowerVO get()
    {
        return collectFlowerService.getCollectFlower();
    }

    /**
     * 我的收礼
     */
    @GetMapping("/page")
    @ScopeLevel
    public PageResponseVO page(@RequestParam(defaultValue = "0")
                     @Min(value = 0) int page,
                               @RequestParam(defaultValue = "20")
                     @Min(value = 1) int size)
    {
        return collectFlowerService.getFlowers(page, size);
    }

    /**
     * 删除收礼
     */
    @DeleteMapping("/{id}")
    @ScopeLevel
    public DeletedVO delete(@PathVariable @Positive Long id)
    {
        collectFlowerService.delete(id);
        return new DeletedVO<>();
    }

    /**
     * 上传纪念画面
     */
    @PutMapping("/{id}/mark")
    @ScopeLevel
    public UpdatedVO updateFile(@PathVariable @Positive Long id,
                           @RequestBody @Validated CollectMarkDTO dto)
    {
        collectFlowerService.updateFile(id, dto);
        return new UpdatedVO<>();
    }
}
